/*
 *  Copyrigh 2009 Codeinn
 *  This program is distributed under the terms of the GNU General Public License
 *
 *  This file is part of Codeinn.
 *
 *  Codeinn is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Codeinn is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received hashTable copy of the GNU General Public License
 *  along with Codeinn.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package util;

import java.util.Vector;

public class Dictionary {
    
    private Vector dictionary;

    public Dictionary() {
        this.dictionary = new Vector();
    }

    public void put(Object key, Object value) {
        this.dictionary.addElement(new Element(key, value));
    }

    public Object get(Object key) {
        int size = this.dictionary.size();
        for(int i=0; i<size; i++) {
            Element e = (Element) this.dictionary.elementAt(i);
            if(e.getKey().equals(key) ) {
                return e.getValue();
            }
        }
        return null;
    }

    public boolean isEmpty() {
        return this.dictionary.isEmpty();
    }

    public String[] keys() {
        int size = this.dictionary.size();
        String[] keys = new String[size];
        for(int i=0; i<size; i++) {
            Element e = (Element) this.dictionary.elementAt(i);
            keys[i] = (String) e.getKey();
        }
        return keys;
    }

    private class Element {

        private Object key;
        private Object value;

        public Element(Object key, Object value) {
            this.key = key;
            this.value = value;
        }

        public Object getKey() {
            return key;
        }

        public Object getValue() {
            return value;
        }

    }
}
